<div class="layuimini-container">
    <form id="app-form" class="layui-form layuimini-form">
        
        <div class="layui-form-item">
            <label class="layui-form-label">砍价商品id</label>
            <div class="layui-input-block">
                <input type="text"   autocomplete="off"  id="goods_id" name="g_id" class="layui-input" lay-verify="required"  placeholder="请输入砍价商品id" value="" >
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">砍价活动名称</label>
            <div class="layui-input-block">
                <input type="text" name="title" class="layui-input" lay-verify="required" placeholder="请输入砍价活动名称" value="">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">砍价活动简介</label>
            <div class="layui-input-block">
                <input type="text" name="info" class="layui-input" lay-verify="required" placeholder="请输入砍价活动简介" value="">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">砍价活动商品库存</label>
            <div class="layui-input-block">
                <input type="text" name="bargain_stock" class="layui-input" lay-verify="required" placeholder="请输入砍价活动商品库存" >
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">商品价格</label>
            <div class="layui-input-block">
                <input type="text" name="price" class="layui-input" lay-verify="required" placeholder="请输入商品价格" value="">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">砍价总人数</label>
            <div class="layui-input-block">
                <input type="text" id ="bargain_num" name="bargain_num" class="layui-input" lay-verify="required" placeholder="请输入砍价总人数" value="0">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">砍价目标金额</label>
            <div class="layui-input-block">
                <input type="text" id = 'bargain_price' name="bargain_price" class="layui-input" lay-verify="required" placeholder="请输入砍价目标金额" value="">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">每次砍的最大金额</label>
            <div class="layui-input-block">
                <input type="text" id="bargain_max_price" autocomplete="off" name="bargain_max_price" class="layui-input" lay-verify="required" placeholder="请输入每次砍的最大金额" value="">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">每次砍的最小金额</label>
            <div class="layui-input-block">
                <input type="text" id ="bargain_min_price" name="bargain_min_price" class="layui-input" lay-verify="required" placeholder="请输入每次砍的最小金额" value="{$row.bargain_max_price|default=''}">
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">砍价规则</label>
            <div class="layui-input-block">
                <input type="text" name="rule" class="layui-input" lay-verify="required" placeholder="请输入砍价规则" value="">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">状态[0:关闭,1:开启]</label>
            <div class="layui-input-block">
                <input type="text" name="status" class="layui-input" lay-verify="required" placeholder="请输入状态[0:关闭,1:开启]" value="0">
            </div>
        </div>
        <div class="hr-line"></div>
        <div class="layui-form-item text-center">
            <button type="submit" class="layui-btn layui-btn-normal layui-btn-sm" lay-submit>确认</button>
            <button type="reset" class="layui-btn layui-btn-primary layui-btn-sm">重置</button>
        </div>

    </form>
</div>



<script src="https://apps.bdimg.com/libs/jquery/2.1.4/jquery.min.js">
</script>
<script>
    function getMasterIds(obj) {
        console.log(obj)
        $("#goods_id").val(obj)
        layer.closeAll();
    }
</script>
<script>
    $('#goods_id').click(function () {

        layui.use("layer", function () {
            var layer = layui.layer;
            layer.open({
                type:2,
                auth: 'add',
                content:'http://www.1902a.com/admin/goods.BargainController/goodsAdd'
            })
        });


    })
</script>
<script>

    $('#bargain_min_price').blur(function () {
        var bargain_price = $('#bargain_price').val()
        var bargain_num = $('#bargain_num').val()
        var bargain_min_price = $('#bargain_min_price').val()
        if( bargain_min_price * bargain_num > bargain_price){
            $('#bargain_min_price').val(0.01)
            alert('最小金额不符合')
        }
    })
    $('#bargain_max_price').blur(function () {
        var bargain_price = $('#bargain_price').val()
        var bargain_num = $('#bargain_num').val()
        var bargain_max_price = $('#bargain_max_price').val()
        if( bargain_max_price * bargain_num > bargain_price){
            $('#bargain_max_price').val( parseInt(bargain_price/bargain_num) )
            alert('最大金额不符合')
        }
    })
</script>